/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#pragma once

/// Omen headers
#include "OmenConfig.h"

#include <IOmenModelFileReader.h>
#include <IOmenModel.h>
#include <IOmenLightSource.h>
#include <IOmenCamera.h>

#include <OmenXmlReader.h>

/// STL headers
#include <string>
#include <vector>

namespace Omen
{

    class OMEN_API ModelFileReader : public IModelFileReader
    {
    private:
        #define ModelFileFormat_Version_1_0 L"1.0"

    public:
        ModelFileReader();
        ModelFileReader( const ModelFileReader& other );
        virtual ~ModelFileReader();

        virtual bool canRead( const std::wstring& filename );        /// <summary>Returns true if this reader can read the given file</summary>
        virtual bool loadFile();                                    /// <summary>Reads the contents of the model file</summary>

        virtual unsigned long getSceneCount() const;                                        /// <summary>Get number of Scenes in the model-file</summary>
        virtual bool getScenes( IScene** const& pListScenes, unsigned int maxSize ) const ; /// <summary>Get the Scenes</summary>

    protected:
        bool         modelFileFormatVersionCompatible( const std::wstring& version ); /// <summary> This function checks whether the file format version is compatible with engine version</summary>
        bool         loadFileXml();         /// <summary>Loads the xml-formatted Omen Model File</summary>
        bool         loadFileBinary();      /// <summary>Loads the binary formatted Omen Model File</summary>

        bool         parseModelFileNode( Omen::XmlNode& node );
        bool         parseSceneNode( Omen::XmlNode& node, Omen::IScene*& pScene );
        bool         parseModelNode( Omen::XmlNode& node, Omen::IModel*& pModel );
        bool         parseMeshNode( Omen::XmlNode& node, Omen::IMesh*& pMesh );

    private:
        typedef struct _VertexData {
            Omen::Float    x, y, z;         /// <summary>vertex coordinates x,y,z<summary>
            Omen::Float    tu,tv;           /// <summary>Texture coordinates u,v</summary>
            Omen::Float    nx,ny,nz;        /// <summmary>Vertex normals nx,ny,nz</summary>
        } VertexData;

        #pragma warning(disable:4251) // Disable warning about private member variable needs to have dll-interface to be used by clients of class 'this'
        std::vector<VertexData> m_vertexData;
        std::wstring    m_modelFileName;
        std::wstring    m_fileFormat;
        std::wstring    m_fileFormatVersion;

        std::vector<Omen::IScene*>    m_listScenes;
        Omen::IScene*                 m_pCurrentScene;
        Omen::IModel*                 m_pCurrentModel;
        #pragma warning(default:4251) // Return the default state of the warning

        Omen::XmlDocument   m_model_doc;
    };
}
